List hot keys for the active form in Access — see what's been assigned — to look up, document, resolve duplicates, and determine what hot keys aren't used yet.
To add a hot key to a form, put & in the Caption where you want the next letter to be underlined and serve as a "hot-key", meaning the user can press ALT+[key] to jump like the mouse was clicked there. Users who are fast on the keyboard love these.
Even though the result shows UPPER or lower case for the hot key, Access makes no distinction for case. A Hot Key can be most anything you can type on the keyboard, not limited to letters — hot key can be a number or a special character too. Caption is text so what you choose is quite liberal. If you want to underline an & then use 2 of them.
VBA includes a procedure to bubble sort a passed array and correlate 2 other passed arrays.
The download contains an ACCDA that is really an Access ACCDB with additional setup so it can be installed as an add-in.
If you don't want to install an addin, import its VBA module, or copy the VBA code from this page to make a module in your application. Then Compile and Save.
Add-ins can be invoked when any Access database is open.
This add-in is a regular ACCDB file that has been renamed to have an ACCDA extension. It may be used freely, but you may not sell it in whole or in part. You may include it in applications you develop for others provided you keep attribution, mark your modifications, and share this source link.
Remember to UNBLOCK files you download to remove the Mark of the Web. Here are steps to do that: https://msaccessgurus.com/MOTW_Unblock.htm
watch on YouTube: How to Make and Install an Access Add-In (11:51)
ListHotKeys_s4p is called when you invoke the add-in. It can also be called on its own if you import this module into your application. While defined as a function, ListHotKeys_s4p could also be a sub since it doesn't return any value.
Option Compare Database Option Explicit '*************** Code Start ***************************************************** ' module name: bas_ListHotKeys_s4p '------------------------------------------------------------------------------- ' Purpose : show a list of hot key assignments in the Debug window ' - see what has been used and resolve conflicts ' - determine what hasn't been used ' Author : crystal (strive4peace) ' web site : https://msaccessgurus.com ' This code: https://msaccessgurus.com/tool/Addin_ListHotKeys.htm ' LICENSE : ' You may freely use and share this code, but not sell it. ' Keep attribution. Mark your changes. Use at your own risk '--- ' you can install this as an addin ' alternately, you can import this module and hook it into your application ' Clearly mark your changes and ' ensure each user has the above link to free source code. '------------------------------------------------------------------------------- ' ListHotKeys_s4p '------------------------------------------------------------------------------- Function ListHotKeys_s4p() '200720, 200825, 230905 'loop through all controls on ActiveForm ' and list Hot Key if Caption property has & 'see what next character is 'load into arry 'sort array alphbetically, correlate related arrays 'CALLs ' SortStringArray3 On Error GoTo Proc_Err Dim ctl As Control _ ,f As Form Dim sCaption As String _ ,sKey As String * 1 _ ,sName As String _ ,sMsg As String _ ,i As Integer _ ,iLenCaption As Integer _ ,iNbrShortcut As Integer _ ,iPos As Integer Dim aKeys() As String _ ,aCaptions() As String _ ,aNames() As String iNbrShortcut = 0 Set f = Screen.ActiveForm With f ReDim aKeys(1 To .Controls.Count) 'more than we'll need ReDim aCaptions(1 To .Controls.Count) 'more than we'll need ReDim aNames(1 To .Controls.Count) 'more than we'll need For Each ctl In .Controls sName = "" With ctl sName = .Name sCaption = .Caption iLenCaption = Len(sCaption) sKey = "" iPos = 1 Do While iPos > 0 And iLenCaption > 0 iPos = InStr(iPos,sCaption, "&") If iPos > 0 _ And iPos + 1 <= iLenCaption Then 'see what next character is iPos = iPos + 1 sKey = Mid(sCaption,iPos) If sKey = "&" Then sKey = "" 'loop to look for next ampersand iPos = iPos + 1 Else iNbrShortcut = iNbrShortcut + 1 aKeys(iNbrShortcut) = sKey aCaptions(iNbrShortcut) = sCaption aNames(iNbrShortcut) = sName iPos = -1 'stop loop End If End If Loop End With 'ctl NextControl: Next ctl End With 'ActiveForm 'done reading values Debug.Print "*** Hot Keys for " & f.Name & " in " & CurrentDb.Name 'if there are hot keys, then sort alphabetically If iNbrShortcut > 0 Then ReDim Preserve aKeys(1 To iNbrShortcut) ReDim Preserve aCaptions(1 To iNbrShortcut) ReDim Preserve aNames(1 To iNbrShortcut) Call SortStringArray3(aKeys,aCaptions,aNames) 'report hot keys sMsg = "hot keys: " & Join(aKeys, ", ") _ & vbCrLf & vbCrLf & "Look at Immediate window for details" For i = 1 To iNbrShortcut Debug.Print aKeys(i); Debug.Print Tab(5); aCaptions(i); Debug.Print Tab(30); aNames(i) Next i Else 'message that not hot keys found sMsg = "No hot keys" End If MsgBox sMsg,, "ListHotKeys_s4p" Proc_Exit: On Error Resume Next Set ctl = Nothing Set f = Nothing Exit Function Proc_Err: If Err.Number = 438 Then Resume NextControl 'doesn't have Caption MsgBox Err.Description,,_ "ERROR " & Err.Number _ & " ListHotKeys_s4p" Resume Proc_Exit 'if you want to single-step code to find error, CTRL-Break at MsgBox 'then right-click on "Resume" and choose --> Set Next Statement 'press F8 to resume with the line that threw the error so you can inspect it Resume End Function '------------------------------------------------------------------------------- ' SortStringArray3 '------------------------------------------------------------------------------- Public Sub SortStringArray3(ByRef pArray() As String _ ,ByRef pArray2() As String _ ,ByRef pArray3() As String _ ) 'Sorts a single element string array ' + rearrange 2 other arrays to correlate - s4p '200724 strive4peace 'based on bubble-sort code originally written by Brent Spaulding Dim s1 As String,s2 As String,s3 As String Dim i As Integer Dim j As Long 'Bubble sort the array If UBound(pArray) > 0 Then j = UBound(pArray) 'loop through process for as many elements as there are Do Until j = 0 'start with next to last element 'if it is greater, then swap them For i = LBound(pArray) To j - 1 If pArray(i) > pArray(i + 1) Then s1 = pArray(i) s2 = pArray2(i) s3 = pArray3(i) 'rewrite element in first array pArray(i) = pArray(i + 1) pArray(i + 1) = s1 'rewrite element in second array to correlate pArray2(i) = pArray2(i + 1) pArray2(i + 1) = s2 'rewrite element in third array to correlate pArray3(i) = pArray3(i + 1) pArray3(i + 1) = s3 End If Next i j = j - 1 Loop End If End Sub '*************** Code End *****************************************************
How to make and install an Access add-in
Screen.ActiveForm property (Access)
Hot keys can save a lot of time for those who are great on the keyboard.
If you have lots of controls with hot keys, it's nice to document them! Copy the results from Immediate window to Word, Excel, or PowerPoint (for instance) and format for documentation.
By seeing what hot keys are assigned (and duplicates, which still work but maybe you would rather change one), you can see what is NOT assigned, and look at whatever you want to put a hot key in to see which character to choose. Run in Design view too.
Although the example didn't have many controls, I've designed much busier forms and the speedy users appreciate being able to jump all over with the keyboard.
If you're developing dynamic Help in your application, You can import and modify the module that gets the hot keys and show results on a form instead. If this code is used in an application that isn't open source, each user must be made aware of this link with the free code to generate the results.
There's just code to run, no menu form. Instead of installing the add-in, to have this capability in your database, you can simply import the module named bas_ListHotKeys_s4p, with two procedures (mark your changes):
You can run ListHotKeys_s4p from Design view too. That's nice while you're developing and assigning hot keys.
In case you're wondering, the database I opened to test the code on, that you see a form from in the big image is an application that's done but not shared publically yet — maybe next.
I wrote it to find something that I couldn't remember where it was. It loops through all the Access database in (and under) a path and writes object names and more. It showed me what I needed to find.
What are you doing with Access?
Let's connect and team-develop while we build your application together. As needed, I'll pull in code and features from my vast libraries, cutting out lots of development time, and you learn how it is done. Each step of the way, you guide from your perspective and infuse your goals and ideas. The melding of what we both can do results in a successful application.
Email me training@msAccessGurus